package com.demo.designmode.test.clonedemo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PersonDeep implements Cloneable{
    
    private String nickname;
    private Address address;
    
    @Override
    protected Object clone() throws CloneNotSupportedException {
    	PersonDeep personDeep = (PersonDeep) super.clone();
        Address address = (Address) personDeep.getAddress().clone();
        personDeep.setAddress(address);
        return personDeep;
    }
    

    
    public static void main(String[] args) {
        
        Address address = new Address("辽源市");
        PersonDeep person= new PersonDeep("李吴哲",address);
        
        try {
            PersonDeep clone = (PersonDeep) person.clone();
            System.out.println(person == clone);
            System.out.println(person.getClass() == clone.getClass());
            System.out.println(person.getAddress() == clone.getAddress());
            System.out.println(person.getAddress().getClass() == clone.getAddress().getClass());
            
        } catch (CloneNotSupportedException e) {
        	e.printStackTrace();
        }
    }


}